/**
 * ReportGear(2011)
 */
package com.reportgear.designer.action.report;

import java.util.EventObject;
import java.util.List;

import net.abbp.report.model.ReportModel;
import net.abbp.report.view.GridView;

import com.reportgear.core.swing.pane.base.JBaseDialog;
import net.abbp.swing.util.ImageUtils;
import com.reportgear.designer.action.UndoableAction;
import com.reportgear.designer.parameter.pane.ParameterEditPane;
import com.reportgear.report.parameter.model.Parameter;

/**
 * 报表参数编辑
 * 
 * @version 1.0 2011-5-1
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class ReportParametersAction extends UndoableAction {
	public ReportParametersAction() {
		setName("报表参数...");
		setMnemonic('A');
		setSmallIcon(ImageUtils.readIcon("report/parameter.gif"));
	}

	@Override
	public boolean executeAction(EventObject evt) {
	    GridView workSheet = this.getGridView();

		if (workSheet == null) {
			return false;
		}

		ParameterEditPane pep = new ParameterEditPane();

		ReportModel model = workSheet.getReportModel();

		pep.populate(model.getParameters());
		if (pep.showInDialog(workSheet) == JBaseDialog.RESULT_OK) {
			List<Parameter> paraList = pep.update();
			model.getParameters().clear();
			model.getParameters().addAll(paraList);

			return true;
		}

		return false;
	}

}
